csv_util.o strptime.o grtcirc.o util_crc.o xmlgeneric.o \
formspec.o xmltag.o cet.o cet_util.o fatal.o rgbcolors.o \
inifile.o garmin_fs.o gbsleep.o units.o @GBSER@ gbser.o \
- gbfile.o parse.o session.o \
+ gbfile.o parse.o session.o src/core/xmlstreamwriter.o \
$(PALM_DB) $(GARMIN) $(JEEPS) $(SHAPE) @ZLIB@ $(FMTS) $(FILTERS)
OBJS = main.o globals.o $(LIBOBJS) @FILEINFO@
filterdefs.h grtcirc.h
sort.o: sort.cc defs.h config.h queue.h zlib/zlib.h zlib/zconf.h gbfile.h \
cet.h cet_util.h inifile.h session.h src/core/datetime.h filterdefs.h
+src/core/xmlstreamwriter.o: src/core/xmlstreamwriter.cc \
+ src/core/xmlstreamwriter.h
stackfilter.o: stackfilter.cc defs.h config.h queue.h zlib/zlib.h \
zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h session.h \
src/core/datetime.h filterdefs.h
{
writer->writeOptionalTextElement("name", oname);
- // FIXME: the replace() nonsense here is to prevent bogus control
- // characters from being embedded in the output stream. The only place
- // this happens in our test suite is a ^Z in the German Garmin GPI test
- // file. Filter that out in the two fields below... Ideally, we should
- // probably filter that in the input rather than here.
-
- QString desc = QString::fromUtf8(waypointp->description);
- desc = desc.replace(QRegExp("[\014-\032]"), " ");
- writer->writeOptionalTextElement("cmt", desc);
+ writer->writeOptionalTextElement("cmt", waypointp->description);
if (waypointp->notes && waypointp->notes[0]) {
- QString note = QString::fromUtf8(waypointp->notes);
- note = note.replace(QRegExp("[\014-\032]"), " ");
- writer->writeTextElement("desc", note);
+ writer->writeTextElement("desc", waypointp->notes);
} else {
- writer->writeOptionalTextElement("desc", QString::fromUtf8(waypointp->description));
+ writer->writeOptionalTextElement("desc", waypointp->description);
}
write_gpx_url(waypointp);
{
fs_xml* fs_gpx;
writer->writeStartElement("rte");
- writer->writeOptionalTextElement("name", QString::fromUtf8(rte->rte_name));
- writer->writeOptionalTextElement("desc", QString::fromUtf8(rte->rte_desc));
+ writer->writeOptionalTextElement("name", rte->rte_name);
+ writer->writeOptionalTextElement("desc", rte->rte_desc);
if (rte->rte_num) {
writer->writeTextElement("number", QString::number(rte->rte_num));
</wpt>
<wpt lat="37.522060037" lon="-122.277670026">
<name>NOTE 1</name>
- <cmt>12 test lines - see notes with GPX sample!! four line widths for solid red two line widths for dashed red seven colors for medium width Note that line names have nothing at all to do with line style attributes!\vThese are named for convenient cross-reference, but keep in mind that "red med" is a line label and "Red Medium" is a style label. Waypoints are generated by Topo to exactly match the first track point. Apparently only GPX and KML output from GPSBabel retain track descriptions??</cmt>
- <desc>12 test lines - see notes with GPX sample!! four line widths for solid red two line widths for dashed red seven colors for medium width Note that line names have nothing at all to do with line style attributes!\vThese are named for convenient cross-reference, but keep in mind that "red med" is a line label and "Red Medium" is a style label. Waypoints are generated by Topo to exactly match the first track point. Apparently only GPX and KML output from GPSBabel retain track descriptions??</desc>
+ <cmt>12 test lines - see notes with GPX sample!!\rfour line widths for solid red\rtwo line widths for dashed red\rseven colors for medium width\rNote that line names have nothing at all to do with line style attributes! These are named for convenient cross-reference,\r but keep in mind that "red med" is a line label and "Red Medium" is a style label.\rWaypoints are generated by Topo to exactly match the first track point.\rApparently only GPX and KML output from GPSBabel retain track descriptions??</cmt>
+ <desc>12 test lines - see notes with GPX sample!!\rfour line widths for solid red\rtwo line widths for dashed red\rseven colors for medium width\rNote that line names have nothing at all to do with line style attributes! These are named for convenient cross-reference,\r but keep in mind that "red med" is a line label and "Red Medium" is a style label.\rWaypoints are generated by Topo to exactly match the first track point.\rApparently only GPX and KML output from GPSBabel retain track descriptions??</desc>
</wpt>
<wpt lat="37.522349358" lon="-122.284910083">
<name>NOTE 2</name>
- <cmt>how GPX from GPSBabel shows Topo track desc as of 2012: (line name and line style are NOT related to actual color or width) <trk> <name>red line</name> <desc>Style=red med, Width=3, Dashed=0, Color=#ff0000</desc> <number>1</number> <trkseg> ... (Topo menu colors are stored in the file as web-style hex RGB) Red=#ff0000, Yellow=#ffff00, Green=#008000, Blue=#000080, Purple=#800080, Black=#000000, White=#ffffff (Topo solid line widths: Hairline=1, Thin=2, Medium=3, Thick=4) (Topo dashed line widths: Hairline=1, Thin=2) SRE's tpo.c mod stuffs Style/Width/Dashed/Color fields into "desc" field under the assumption that something will post-process GPX or KML output and move information from desc to private extensions (solid lines have "Dashed=0", can have width of 1=hairline to 4=thick) (dashed lines have "Dashed=1", can only have width of 1=hairline or 2=thin) </cmt>
- <desc>how GPX from GPSBabel shows Topo track desc as of 2012: (line name and line style are NOT related to actual color or width) <trk> <name>red line</name> <desc>Style=red med, Width=3, Dashed=0, Color=#ff0000</desc> <number>1</number> <trkseg> ... (Topo menu colors are stored in the file as web-style hex RGB) Red=#ff0000, Yellow=#ffff00, Green=#008000, Blue=#000080, Purple=#800080, Black=#000000, White=#ffffff (Topo solid line widths: Hairline=1, Thin=2, Medium=3, Thick=4) (Topo dashed line widths: Hairline=1, Thin=2) SRE's tpo.c mod stuffs Style/Width/Dashed/Color fields into "desc" field under the assumption that something will post-process GPX or KML output and move information from desc to private extensions (solid lines have "Dashed=0", can have width of 1=hairline to 4=thick) (dashed lines have "Dashed=1", can only have width of 1=hairline or 2=thin) </desc>
+ <cmt>how GPX from GPSBabel shows Topo track desc as of 2012:\r(line name and line style are NOT related to actual color or width)\r\r<trk>\r <name>red line</name>\r <desc>Style=red med, Width=3, Dashed=0, Color=#ff0000</desc>\r<number>1</number>\r<trkseg>\r...\r(Topo menu colors are stored in the file as web-style hex RGB)\r Red=#ff0000, Yellow=#ffff00, Green=#008000, Blue=#000080,\r Purple=#800080, Black=#000000, White=#ffffff\r(Topo solid line widths: Hairline=1, Thin=2, Medium=3, Thick=4)\r(Topo dashed line widths: Hairline=1, Thin=2)\rSRE's tpo.c mod stuffs Style/Width/Dashed/Color fields into "desc" field\r under the assumption that something will post-process GPX or KML output\r and move information from desc to private extensions\r(solid lines have "Dashed=0", can have width of 1=hairline to 4=thick)\r(dashed lines have "Dashed=1", can only have width of 1=hairline or 2=thin)\r</cmt>
+ <desc>how GPX from GPSBabel shows Topo track desc as of 2012:\r(line name and line style are NOT related to actual color or width)\r\r<trk>\r <name>red line</name>\r <desc>Style=red med, Width=3, Dashed=0, Color=#ff0000</desc>\r<number>1</number>\r<trkseg>\r...\r(Topo menu colors are stored in the file as web-style hex RGB)\r Red=#ff0000, Yellow=#ffff00, Green=#008000, Blue=#000080,\r Purple=#800080, Black=#000000, White=#ffffff\r(Topo solid line widths: Hairline=1, Thin=2, Medium=3, Thick=4)\r(Topo dashed line widths: Hairline=1, Thin=2)\rSRE's tpo.c mod stuffs Style/Width/Dashed/Color fields into "desc" field\r under the assumption that something will post-process GPX or KML output\r and move information from desc to private extensions\r(solid lines have "Dashed=0", can have width of 1=hairline to 4=thick)\r(dashed lines have "Dashed=1", can only have width of 1=hairline or 2=thin)\r</desc>
</wpt>
<wpt lat="37.522691488" lon="-122.288962007">
<name>NOTE 3</name>
- <cmt>how KML from GPSBabel shows Topo track desc as of 2012: (see important notes with GPX sample, all of them apply here!) (note that GPSBabel forces all track styles to be the same - why?) <Folder> <name>Tracks</name> <Folder> <name>red line</name> <snippet/> <description> <![CDATA[<table> <tr><td><b>Description</b> Style=Red Medium, Width=3, Dashed=0, Color=#ff0000 </td></tr> <tr><td><b>Distance</b> 1.3 mi </td></tr> </table>]]> </description> <Folder> <name>Points</name> <Placemark> <name>red line-0</name> ...</cmt>
- <desc>how KML from GPSBabel shows Topo track desc as of 2012: (see important notes with GPX sample, all of them apply here!) (note that GPSBabel forces all track styles to be the same - why?) <Folder> <name>Tracks</name> <Folder> <name>red line</name> <snippet/> <description> <![CDATA[<table> <tr><td><b>Description</b> Style=Red Medium, Width=3, Dashed=0, Color=#ff0000 </td></tr> <tr><td><b>Distance</b> 1.3 mi </td></tr> </table>]]> </description> <Folder> <name>Points</name> <Placemark> <name>red line-0</name> ...</desc>
+ <cmt>how KML from GPSBabel shows Topo track desc as of 2012:\r(see important notes with GPX sample, all of them apply here!)\r(note that GPSBabel forces all track styles to be the same - why?)\r\r <Folder>\r <name>Tracks</name>\r <Folder>\r <name>red line</name>\r <snippet/>\r <description>\r<![CDATA[<table>\r <tr><td><b>Description</b> Style=Red Medium, Width=3, Dashed=0, Color=#ff0000 </td></tr>\r <tr><td><b>Distance</b> 1.3 mi </td></tr>\r </table>]]>\r </description>\r <Folder>\r <name>Points</name>\r <Placemark>\r <name>red line-0</name>\r...</cmt>
+ <desc>how KML from GPSBabel shows Topo track desc as of 2012:\r(see important notes with GPX sample, all of them apply here!)\r(note that GPSBabel forces all track styles to be the same - why?)\r\r <Folder>\r <name>Tracks</name>\r <Folder>\r <name>red line</name>\r <snippet/>\r <description>\r<![CDATA[<table>\r <tr><td><b>Description</b> Style=Red Medium, Width=3, Dashed=0, Color=#ff0000 </td></tr>\r <tr><td><b>Distance</b> 1.3 mi </td></tr>\r </table>]]>\r </description>\r <Folder>\r <name>Points</name>\r <Placemark>\r <name>red line-0</name>\r...</desc>
</wpt>
<wpt lat="37.522104979" lon="-122.272938490">
<name>NOTE 4</name>
- <cmt>how MapSource 6.16.3 adds color to a track as of 2012: (color choices are Dark Gray, Red, Green, Yellow, Blue, Magenta, Cyan, White, Transparent) (should be easy to turn desc tag into their extension, but better to directly write track styles) <trk> <name>Hwy 50 from Placerville</name> <extensions> <gpxx:TrackExtension xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3"> <gpxx:DisplayColor>Red</gpxx:DisplayColor> </gpxx:TrackExtension> </extensions> <trkseg> ... </cmt>
- <desc>how MapSource 6.16.3 adds color to a track as of 2012: (color choices are Dark Gray, Red, Green, Yellow, Blue, Magenta, Cyan, White, Transparent) (should be easy to turn desc tag into their extension, but better to directly write track styles) <trk> <name>Hwy 50 from Placerville</name> <extensions> <gpxx:TrackExtension xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3"> <gpxx:DisplayColor>Red</gpxx:DisplayColor> </gpxx:TrackExtension> </extensions> <trkseg> ... </desc>
+ <cmt>how MapSource 6.16.3 adds color to a track as of 2012:\r(color choices are Dark Gray, Red, Green, Yellow, Blue, Magenta, Cyan, White, Transparent)\r(should be easy to turn desc tag into their extension, but better to directly write track styles)\r\r <trk>\r <name>Hwy 50 from Placerville</name>\r <extensions>\r <gpxx:TrackExtension xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3">\r <gpxx:DisplayColor>Red</gpxx:DisplayColor>\r </gpxx:TrackExtension>\r </extensions>\r <trkseg>\r...\r</cmt>
+ <desc>how MapSource 6.16.3 adds color to a track as of 2012:\r(color choices are Dark Gray, Red, Green, Yellow, Blue, Magenta, Cyan, White, Transparent)\r(should be easy to turn desc tag into their extension, but better to directly write track styles)\r\r <trk>\r <name>Hwy 50 from Placerville</name>\r <extensions>\r <gpxx:TrackExtension xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3">\r <gpxx:DisplayColor>Red</gpxx:DisplayColor>\r </gpxx:TrackExtension>\r </extensions>\r <trkseg>\r...\r</desc>
</wpt>
<trk>
<name>red thick</name>
--- /dev/null
+/*
+ Copyright (C) 2013 Robert Lipe, gpsbabel.org
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
+
+ */
+
+#include <src/core/xmlstreamwriter.h>
+#include <QtCore/QtGlobal>
+
+#include <QtCore/QFile>
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
+#include <QtCore/QRegExp>
+#else
+#include <QtCore/QRegularExpression>
+#endif
+#include <QtCore/QXmlStreamWriter>
+
+// As this code began in C, we have several hundred places that write
+// c strings. Add a test that the string contains anything useful
+// before serializing an empty tag.
+// We also strip out characters that are illegal in xml. These can creep
+// into our structures from other formats where they are legal.
+
+namespace gpsbabel
+{
+
+XmlStreamWriter:: XmlStreamWriter(QString* s) : QXmlStreamWriter(s) {}
+
+XmlStreamWriter::XmlStreamWriter(QFile* f) : QXmlStreamWriter(f) {}
+
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
+QRegExp XmlStreamWriter::badXml10 = QRegExp("[\\x0000-\\x0008]|[\\x000b-\\x000c]|[\\x000e-\\x001f]");
+#else
+QRegularExpression XmlStreamWriter::badXml10 = QRegularExpression("[\\x00-\\x08]|[\\x0b-\\x0c]|[\\x0e-\\x1f]");
+#endif
+
+// Dont emit the attribute if there's nothing interesting in it.
+void XmlStreamWriter::writeOptionalAttribute(const QString& qualifiedName, QString value)
+{
+ if (!value.isEmpty()) {
+ QXmlStreamWriter::writeAttribute(qualifiedName, value.replace(badXml10, " "));
+ }
+}
+
+// Dont emit the element if there's nothing interesting in it.
+void XmlStreamWriter::writeOptionalTextElement(const QString& qualifiedName, QString text)
+{
+ if (!text.isEmpty()) {
+ QXmlStreamWriter::writeTextElement(qualifiedName, text.replace(badXml10, " "));
+ }
+}
+
+void XmlStreamWriter::writeAttribute(const QString& qualifiedName, QString value)
+{
+ QXmlStreamWriter::writeAttribute(qualifiedName, value.replace(badXml10, " "));
+}
+
+void XmlStreamWriter::writeCDATA(QString text)
+{
+ QXmlStreamWriter::writeCDATA(text.replace(badXml10, " "));
+}
+
+void XmlStreamWriter::writeCharacters(QString text)
+{
+ QXmlStreamWriter::writeCharacters(text.replace(badXml10, " "));
+}
+
+void XmlStreamWriter::writeTextElement(const QString& qualifiedName, QString value)
+{
+ QXmlStreamWriter::writeTextElement(qualifiedName, value.replace(badXml10, " "));
+}
+
+} // namespace gpsbabel
*/
-#include <QtCore/QFile>
-#include <QtCore/QXmlStreamWriter>
+#ifndef XMLSTREAMWRITER_H
+#define XMLSTREAMWRITER_H
-// As this code began in C, we have several hundred places that write
-// c strings. Add a test that the string contains anything useful
-// before serializing an empty tag.
+#include <QtCore/QtGlobal>
+#include <QtCore/QXmlStreamWriter>
-namespace gpsbabel {
+class QFile;
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
+class QRegExp;
+#else
+class QRegularExpression;
+#endif
+
+namespace gpsbabel
+{
+
+class XmlStreamWriter : public QXmlStreamWriter
+{
+private:
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
+ static QRegExp badXml10;
+#else
+ static QRegularExpression badXml10;
+#endif
-class XmlStreamWriter : public QXmlStreamWriter {
public:
- XmlStreamWriter(QString* s) : QXmlStreamWriter(s) {}
- XmlStreamWriter(QFile* f) : QXmlStreamWriter(f) {}
-
- // Dont emit the attribute if there's nothing interesting in it.
- void writeOptionalAttribute(QString tag, QString value) {
- if (!value.isEmpty()) {
- writeAttribute(tag, value);
- }
- }
-
- // Dont emit the tag if there's nothing interesting in it.
- void writeOptionalTextElement(QString tag, QString value) {
- if (!value.isEmpty()) {
- writeTextElement(tag, value);
- }
- }
+ XmlStreamWriter(QString* s);
+ XmlStreamWriter(QFile* f);
+
+ void writeOptionalAttribute(const QString& qualifiedName, QString value);
+ void writeOptionalTextElement(const QString& qualifiedName, QString text);
+ void writeAttribute(const QString& qualifiedName, QString value);
+ void writeCDATA(QString text);
+ void writeCharacters(QString text);
+ void writeTextElement(const QString& qualifiedName, QString value);
};
-}; // namespace gpsbabel
+} // namespace gpsbabel
+
+#endif // XMLSTREAMWRITER_H
+